home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / adikit.arc / DGDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-12-01  |  5.4 KB  |  191 lines

  1. /*
  2.  
  3.         Autodesk Device Interface/ADI Driver for Microsoft Mouse
  4.  
  5.         Now it's time to try this thing,
  6.         and hope it works for me.
  7.         Microsoft, Microsoft,
  8.         M-O-U-S-E!
  9.  
  10.         Original driver designed and implemented in January 1984.
  11.         Converted to ADI format September 1986
  12. */
  13.  
  14. #include    "stdio.h"
  15. #include    "dos.h"
  16. #include    "adi.h"
  17. #include    "dgadi.h"
  18. #define VERSION     "1.00"
  19. #define REVDATE     "10/28/86"
  20.  
  21. /*   Default interrupt vector for digitizer drivers is 0x79.  This is
  22.      selectable by user during AutoCAD configuration.  AutoSketch uses
  23.      0x79 only.  */
  24.  
  25. #define VECTOR      0x79              /* Interrupt vector used for messages */
  26. #define iabs(x)     ((x)<0 ? -(x) : (x)) /* integer absolute value */
  27.  
  28. static struct comreg acad;
  29.  
  30. /*  Registers defined as mouse input and output values per Microsoft Mouse
  31.     Installation and Operation Manual 8808-100-00 P/N 99F37B Chapter 4  */
  32.  
  33. struct XREG r;
  34.  
  35. #define m1 r.ax
  36. #define m2 r.bx
  37. #define m3 r.cx
  38. #define m4 r.dx
  39.  
  40. /*  Default slow/fast/threshold values */
  41. static int mi_slow = 25, mi_fast = 50, mi_thresh = 9;
  42.  
  43. struct {int mdadr, mdseg;} mdp;
  44.  
  45. static int prior = 0, enabled = 0, c;
  46. static int x = 0, y = 0;
  47. #define dgx   acad.arg1
  48. #define dgy   acad.arg2
  49.  
  50. main(argc,argv)
  51.   int argc;
  52.   char *argv[];
  53. {
  54.     printf("\n--- Autodesk Device Interface/ADI Driver ---\n");
  55.     printf("Microsoft Mouse driver Vers. %s installed as INT %03xh.",VERSION,VECTOR);
  56.     printf("\nSample ADI Driver created %s by Autodesk, Inc.\n",REVDATE);
  57.  
  58.     /* ADI driver developer should include name of company, or company and
  59.        individual, responsible for creation of ADI device driver and date
  60.        of driver creation to aid in identifying driver. */
  61.  
  62.     while (1)
  63.     {
  64.        iwait(VECTOR, &acad, &acad);
  65. #ifdef  DEBUG
  66.        printf("\n ** Digitizer(%d):  %d(%04x), %d(%04x), %d(%04x) **",
  67.               acad.code, acad.arg1, acad.arg1, acad.arg2, acad.arg2, acad.arg3, acad.arg3);
  68. #endif
  69.        switch (acad.code) 
  70.        {
  71.        case INIT:
  72.           if (acad.arg1 != INTLEVEL)  /* Acceptable interface? */
  73.           {
  74.              acad.code = 0;           /* Nope...return error */
  75.              break;                   /* and get out right now */
  76.           }
  77.  
  78.           /*  Now before we call the supposedly-installed mouse 
  79.               driver, let's look before we leap and see if the interrupt
  80.               vector is really there.  The following code reads the 
  81.               interrupt vector from page zero and makes sure it's at 
  82.               least nonzero before we try the mouse.   */
  83.  
  84.           peek(0, 51<<2, &mdp, sizeof mdp);
  85.  
  86.           if (mdp.mdadr == 0 || mdp.mdseg==0)
  87.              m1=0;
  88.           else
  89.              mouse(0);                /*  Initialise the mouse  */
  90.           if (m1 == 0)
  91.              printf(/*MSG5*/"\nMouse is not installed.");
  92.           else
  93.              enabled=1;
  94.           acad.code = enabled;
  95.           acad.arg1 = 0;              /* We're a mouse-kill tablet stuff */
  96.           acad.arg2 = 0;              /* Everything we say is significant */
  97.           break;
  98.  
  99.        case TERM:
  100.           break;
  101.  
  102.        case SENSE:
  103.  
  104.           /*  Digitizer input call:  returns status values of:
  105.  
  106.               0:  No valid point digitized
  107.               2:  (bx, cx) is a tracking coordinate pair
  108.               3:  (bx, cx) is a point select coordinate pair
  109.               4:  (bx) is a button number 
  110.               5:  (bx) is a button number; (cx, dx) is a coordinate
  111.                   pair giving the location at which the button was
  112.                   pressed   
  113.           */
  114.  
  115.           if (!enabled)
  116.           {
  117.              acad.code = 0;           /*  Dead mouse.  Return no sample  */
  118.              break;
  119.           }
  120.  
  121.           /*  If we returned a menu selection last time, now return the
  122.               reading that came with it:  */
  123.  
  124.           if (prior == 4)
  125.           {
  126.              dgx = x; dgy = y;
  127.              acad.code = (prior = 5);
  128.              break;
  129.           }
  130.  
  131.           mouse(3);
  132.           c=m2 & 0x03;
  133.           mouse(11);
  134.  
  135.           /*  Wait for button release after select. */
  136.  
  137.           if (prior > 2 && c != 0)
  138.           {
  139.              acad.code = 0;
  140.              break;
  141.           }
  142.  
  143.           /*  Convert sample to absolute */
  144.  
  145.           cupd(m3, &x);
  146.           cupd(-m4, &y);              /*  Down is positive.  Neat, huh?  */
  147.  
  148.           /*  All button bits clear indicates tracking coordinate,
  149.               Bit 0 = left button   = point select
  150.                   1 = right button = menu item 0  */
  151.  
  152.           if (c & 0x02)
  153.           {
  154.              prior = 4;               /* Menu item. */
  155.              dgx = 0;
  156.           }
  157.           else
  158.           {
  159.              dgx = x; dgy = y;        /* Point. */
  160.              prior = c ? 3 : 2;
  161.           }
  162.           acad.code = prior;
  163.           break;
  164.        }                              /* end SWITCH */
  165.     }                                 /* end WHILE */
  166. }
  167.  
  168.  
  169. /*  Convert relative coordinate to absolute  */
  170.  
  171. static cupd(chg, pc)
  172.   int chg;
  173.   int *pc;
  174. {
  175.     *pc += chg * ((iabs(chg) > mi_thresh) ?
  176.             mi_fast : mi_slow);
  177.     if (*pc < 0)
  178.        *pc  = 0;
  179.     if (*pc > 20480)
  180.        *pc = 20480;
  181. }
  182.  
  183. /*  MOUSE  --  Send a function to the mouse  */
  184.  
  185. static mouse(fcn)
  186.   int fcn;
  187. {
  188.     m1=fcn;
  189.     int86(51,&r,&r);
  190. }
  191.